/*
 * @(#)Log.java        0.1 09/04/29
 * @version 	0.1 29 Apr 2009
 * @author 	Tran Dai Hiep
 * 
 * Luu tru thong tin de Undo va reo
 * Do co loi nen da huy bo phan nay
 */



package Data;

import java.util.*;

public class Log {	
	private static Log instance = new Log();
	public static Log getInstance() {
		return instance;
	}
	
	protected Log() {
		versions = new Version[SIZE_OF_LOG];
		size = 0;
		index = -1;
	}
	
	
	private Version[] versions;
	private int size, index;
	private final int SIZE_OF_LOG = 30;
	
	public void push(LinkedList<Class> c, LinkedList<Line> l) {
		/*if (index == SIZE_OF_LOG - 1) {
			for (int i = 0; i < SIZE_OF_LOG - 1; i++) {
				versions[i] = versions[i + 1];
			}
			index--;
		}
		index++;
		versions[index] = new Version(c, l);
		size = index + 1;*/
	}
	
	public Version getPrevious() {
		if (!canGetPrevious()) {
			System.out.print("sdf");
			return null;
		}
		else {
			return versions[index--];
		}
	}
	
	public Version getNext() {
		if (!canGetNext()) return null;
		else {
			return versions[++index];
		}
	}
	
	public boolean canGetPrevious() {
		return (index < 1 ? false : true);
	}
	
	public boolean canGetNext() {
		return (index >= size - 1 ? false : true);
	}
	
	public void reset() {
		versions = new Version[SIZE_OF_LOG];
		size = 0;
		index = -1;
	}
	
	LinkedList copy(LinkedList c) {
		LinkedList tmp = new LinkedList();
		for (int i = 0; i < c.size(); i++) {
			tmp.addLast(new Class((Class)c.get(i)));
		}
		return tmp;
	}
}
